package com.you.atlas.web.place.module.screen;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.Navigator.RedirectParameters;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.CommentService;
import com.you.common.webx.AuthContext;
import com.you.place.dal.dao.dataobject.CommentDO;

public class CommentDelete {

    @Autowired
    private CommentService commentService;

    public void execute(@Param("commentId") Long commentId, @Param("pageNo") String pageNo, Navigator navigator) {
        Long memberId = AuthContext.getContext().getMemberId();
        CommentDO commentDO = (CommentDO) commentService.deleteComment(commentId, memberId).getModule();

        if (commentDO == null) {
            return;
        }

        if (commentDO.getType().equals("photo")) {
            RedirectParameters photoView = navigator.redirectTo("placeModule").withTarget("photoView.vm");
            photoView.withParameter("id", commentDO.getFkId().toString()).withParameter("pageNo", pageNo);
        } else {
            RedirectParameters noteView = navigator.redirectTo("placeModule").withTarget("noteView.vm");
            noteView.withParameter("id", commentDO.getFkId().toString()).withParameter("pageNo", pageNo);
        }
    }
}
